package butines.game.steering.behavior;

import java.util.Collection;

import butines.core.math2d.Vector2D;
import butines.game.steering.Vehicle;

public class CohesionBehavior extends AbstractBehavior {

	private Vehicle owner;
	private Collection<? extends Vehicle> neighbors;
	private Vector2D steeringForce = new Vector2D();

	public CohesionBehavior(Vehicle owner) {
		if (owner == null) {
			throw new IllegalArgumentException("Argument 'owner' is null");
		}
		this.owner = owner;
	}

	@Override
	public Vector2D calculate() {
		if (neighbors == null) {
			return steeringForce.set(0, 0);
		}
		cohesion(steeringForce, owner, neighbors);
		return steeringForce.mult(getWeight());
	}

	public Vector2D getSteeringForce() {
		return steeringForce;
	}

	public Collection<? extends Vehicle> getNeighbors() {
		return neighbors;
	}

	public void setNeighbors(Collection<? extends Vehicle> neighbors) {
		this.neighbors = neighbors;
	}
	
}